const dictionaries = [
  { id: 1, key: "default", value: "Default", lable: "默认" },
  { id: 2, key: "article", value: "Article", lable: "文章" },
  { id: 3, key: "product", value: "Product", lable: "商品" },
  { id: 4, key: "page", value: "Page", lable: "单页" },
]
const classify = {}
module.exports = [
  {
    url: "/vue-admin-template/table/classify\.*",
    type: 'get',
    response: config => {
      const { page = 1, limit = 10, key } = config.query
      const lists = classify[key]
      if (lists) {
        const list = [...lists].reverse();
        const index = (page - 1) * limit;
        const howmany = limit
        const data = list.splice(index, howmany)
        return {
          code: 200,
          data: {
            total: list.length,
            lists: data
          }
        }
      } else {
        return {
          code: 200,
          data: {
            total: [].length,
            lists: []
          }
        }
      }


    },
  },
  {
    url: '/vue-admin-template/table/dictionaries',
    type: 'get',
    response: config => {
      return {
        code: 200,
        data: {
          total: dictionaries.length,
          lists: dictionaries
        }
      }
    }
  },
  //deleteUser
  {
    url: '/vue-admin-template/dictionaries/create',
    type: 'post',
    response: config => {
      let { id } = config.body
      if (id) {
        id = Number(id)
        config.body.id = id
        let index = dictionaries.map(val => val.id).indexOf(id)
        dictionaries[index] = config.body

      } else {
        config.body.id = + new Date()
        config.body.c_time = new Date().format('yyyy-mm-dd hh:mm:ss')
        dictionaries.push(config.body)
      }
      return {
        code: 20000,
        data: !id ? '添加成功' : "修改成功"
      }
    }
  },
  // user router
  {
    url: '/vue-admin-template/dictionaries/delete',
    type: 'post',
    response: config => {
      let { id } = config.body;
      const list = [...dictionaries];
      id = Number(id)
      const index = list.map(val => val.id).indexOf(id);
      if (index > -1) {
        dictionaries.splice(index, 1)
        return {
          code: 200,
          data: '删除成功'
        }
      }

      else {
        return {
          code: 40000,
          data: '删除失败'
        }
      }
    }
  },
]
